package com.kang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.entity.SysRole;
import com.kang.mapper.SysRoleMapper;
import com.kang.service.SysRoleService;
import com.kang.vo.SysRoleQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> findAll() {
        return baseMapper.selectList(null);
    }

    @Override
    public Integer removeRole(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public IPage<SysRole> findQueryRole(Long page, Long limit, SysRoleQueryVo sysRoleQueryVo) {
        IPage<SysRole> pageParam = new Page<>(page,limit);
        return sysRoleMapper.selectPage(pageParam,sysRoleQueryVo);
    }

    @Override
    public Integer saveRole(SysRole sysRole) {
        return baseMapper.insert(sysRole);
    }

    @Override
    public Integer updateRole(SysRole sysRole) {
        return baseMapper.updateById(sysRole);
    }

    @Override
    public Integer batchDeleteRole(List<String> ids) {
        return baseMapper.deleteBatchIds(ids);
    }

    @Override
    public SysRole getRoleById(Long id) {
        return sysRoleMapper.selectById(id);
    }
}
